import { EnoadNotifaction } from "../../index";
import DataResource from "../module/DataResource";
import { ActionType } from "../../index";

export function init(componentId: string, data: DataResource) {
  if (data) {
    return {
      type: ActionType.OBJECT_LIST_INIT,
      componentId,
      data: data.getData(),
    };
  }
}

export function open(
  componentId: string,
  item: { uuid: string; id: string; name: string }
) {
  return (dispatch: Function) => clickOpen(dispatch, componentId, item);
}

async function clickOpen(
  dispatch: Function,
  componentId: string,
  item: { uuid: string; id: string; name: string }
) {
  dispatch({
    type: ActionType.OBJECT_LIST_UPDATE,
    componentId,
    data: item,
  });
  //点击调用该方法，进行通知。
  EnoadNotifaction.getInstance().sendMsg(
    "ObjectList",
    "点击了这里" + item.name
  );
}
